package com.gzdh.tang.modu.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gzdh.tang.modu.entity.TangOrder;
import com.gzdh.tang.modu.mapper.TangOrderMapper;
import com.gzdh.tang.modu.model.DeviceCarModel;
import com.gzdh.tang.modu.model.ReportModel;
import com.gzdh.tang.modu.service.TangOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class TangOrderServiceImpl extends ServiceImpl<TangOrderMapper, TangOrder> implements TangOrderService {

    @Autowired
    TangOrderMapper orderMapper;

    @Override
    public String getLiuShui() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String liushui = orderMapper.getDhLiuShui(simpleDateFormat.format(new Date()));
        orderMapper.insertDhLiuShui(0, simpleDateFormat.format(new Date()), liushui);
        return "A" + liushui;
    }


    @Override
    public DeviceCarModel getDeviceCarModel(String orders) {
        return orderMapper.queryDeviceCar(orders);
    }


    @Override
    public List<DeviceCarModel> getDeviceCarModelForList(String orders) {
        return orderMapper.queryDeviceCarForList(orders);
    }

    @Override
    public int updateTangOrderPayChannel(String id, int payChannel) {
        return orderMapper.updateTangOrderPayChannel(payChannel, id);
    }

    @Override
    public int updateTangOrderPayChannelByOrders(String orders, int payChannel) {
        return orderMapper.updateTangOrderPayChannelByOrders(payChannel, orders);
    }

    @Override
    public List<ReportModel> getReportModel(int addr, String startTime, String endTime,String posnum) {
        List<ReportModel> reportModelList = orderMapper.getReport2(addr, startTime, endTime,posnum);
        for (ReportModel goo : reportModelList) {
            int payChannel = goo.getPayChannel();
            switch (payChannel){
                case 0:
                case 2:
                    goo.setPayChannel(3);
                    break;
                case 3:
                    goo.setPayChannel(1);
                    break;
            }
        }
        return reportModelList;
    }

    @Override
    public int updateOrderPayState(String id, int payState) {
        return orderMapper.updateOrderPayState(id, payState);
    }

    @Override
    public int updateTangOrderPayStateByOrders(String orders, int payState) {
        return  orderMapper.updateTangOrderPayStateByOrders(payState, orders);
    }

    @Override
    public int updateOrderNoticeReserve(String id) {
        return orderMapper.updateOrderNoticeReserve(id);
    }

    @Override
    public List<TangOrder> getTangOrder() {
        return null;
    }
}
